﻿using IQReportes.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace IQReportes.Utils
{
    /// <summary>
    /// Html custom helpers
    /// </summary>
    public static class HtmlHelpers
    {
        //{0} button class {1}num modulo {2} idTipoChart , {3} icono de chart
        /// <summary>
        /// plantilla de boton tipo chart
        /// </summary>
        static string buttonTipoChart = @"<button type='button' class='{0}'
                                    id='radioModulo{1}_{2}' onclick = 'cambiarChart({2},{1})'>
                                    <i class='{3}'></i></button>";
        //pie, column, line, table
        /// <summary>
        /// iconos de tipo chart
        /// </summary>
        static string[] iconosTipoChart = { "icomoon-pie", "icomoon-bars", "icomoon-stats", "icomoon-table" };
        /// <summary>
        /// clase de boton tipo chart
        /// </summary>
        static string buttonTipoChartClass = "btn ";
        /// <summary>
        /// inicio de grupo tipo chart
        /// </summary>
        static string inicioButtonTipoChart = "<span><span class='btn-group' data-toggle='buttons-radio'>";
        /// <summary>
        /// fin de grupo tipo chart
        /// </summary>
        static string finButtonTipoChart = "</span></span";
        /// <summary>
        /// obtener html de botones tipo chart
        /// </summary>
        /// <param name="helper">helper</param>
        /// <param name="radioTiposChart">valores de tipo chart</param>
        /// <param name="modulo">módulo</param>
        /// <param name="seleccion">selección</param>
        /// <returns>html de botones tipo chart</returns>
        public static MvcHtmlString BotonesTipoChart(this HtmlHelper helper, List<ComboValores> radioTiposChart, int modulo, int seleccion)
        {
            //Model.radioTiposChart,numModulo
            var sb = new StringBuilder();
            sb.Append(inicioButtonTipoChart);
            for (int i = 0; i < radioTiposChart.Count; i++)
            {
                var active = "";
                if (radioTiposChart[i].id == seleccion)
                {
                    active = "active";
                }
                sb.AppendFormat(buttonTipoChart, buttonTipoChartClass + active, modulo, radioTiposChart[i].id, iconosTipoChart[i]);
            }
            sb.Append(finButtonTipoChart);
            return new MvcHtmlString(sb.ToString());
        }

        /// <summary>
        /// plantilla de botón de descarga
        /// </summary>
        static string buttonDescargaTemplate = @"<span><button type='button' class='{0}' onclick='descargar({1})'><span class='{2}'></span></button></span>";
        /// <summary>
        /// clase de botón de descarga
        /// </summary>
        static string buttonDescargaClass = "btn";
        /// <summary>
        /// ícono de descarga
        /// </summary>
        static string iconoDescarga = "icon-download-alt";
        /// <summary>
        /// obtener html de botón de descarga
        /// </summary>
        /// <param name="helper">helper</param>
        /// <param name="modulo">módulo</param>
        /// <param name="puedeDescargar">posiblidad de descarga</param>
        /// <returns>html de botón de descarga</returns>
        public static MvcHtmlString BotonDescarga(this HtmlHelper helper, int modulo, bool puedeDescargar)
        {
            var sb = new StringBuilder();
            string clase = buttonDescargaClass + (puedeDescargar == true ? "" : " disabled");
            sb.AppendFormat(buttonDescargaTemplate, clase, modulo, iconoDescarga);
            return new MvcHtmlString(sb.ToString());
        }
        static string mobileTipoChart = @"<li><a href='#' onclick='cambiarChart({0},{1})'><i class={2}></i></a></li>";
        static string mobileInicio = @"<div class='btn-group hidden-pc'>
                                            <button class='btn'><i class='icon-wrench'></i></button>
                                            <button class='btn dropdown-toggle' data-toggle='dropdown'>
                                                <span class='caret'></span>
                                            </button>
                                    <ul class='dropdown-menu' id='dropdownTipoChart'>";
        static string mobileFin = @"</ul>    
                                    </div>";
        static string[] mobileIconosTipoChart = { "icomoon-pie", "icomoon-bars", "icomoon-stats", "icomoon-table" };
        public static MvcHtmlString MobileTipoChart(this HtmlHelper helper, List<ComboValores> radioTiposChart, int modulo, int seleccion){
            var sb = new StringBuilder();
            sb.Append(mobileInicio);
            for (int i = 0; i < radioTiposChart.Count; i++)
            {
                sb.AppendFormat(mobileTipoChart, radioTiposChart[i].id,modulo, mobileIconosTipoChart[i]);
            }
            sb.Append(mobileFin);
            return new MvcHtmlString(sb.ToString());
        }
    }

}